package logic

import (
	"context"
	"shopping-mall/shopping_rpc/shoppingrpcclient"

	"shopping-mall/api/internal/svc"
	"shopping-mall/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateProductClassLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateProductClassLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProductClassLogic {
	return &UpdateProductClassLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateProductClassLogic) UpdateProductClass(req *types.UpdateProductClassRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	class, err := l.svcCtx.ShopRpc.UpdateProductClass(l.ctx, &shoppingrpcclient.UpdateProductClassRequest{
		UserId:         req.UserID,
		ProductClassId: req.ProductClassID,
		Name:           req.Name,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "分类修改成功",
		Data:    class,
	}, nil
}
